package hutech.ksv.view;

import hutech.ksv.common.KenhSinhVienContants;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("session")
public class LeftMenuManagedBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	UserLoginManagedBean userLoginManagedBean;
	
	private String isChuNhaTro;
	private String isChuQuanAn;
	private String isCongTy;


	public String getIsChuNhaTro() {
		return isChuNhaTro;
	}



	public void setIsChuNhaTro(String isChuNhaTro) {
		this.isChuNhaTro = isChuNhaTro;
	}



	public String getIsChuQuanAn() {
		return isChuQuanAn;
	}



	public void setIsChuQuanAn(String isChuQuanAn) {
		this.isChuQuanAn = isChuQuanAn;
	}



	public String getIsCongTy() {
		return isCongTy;
	}



	public void setIsCongTy(String isCongTy) {
		this.isCongTy = isCongTy;
	}



	public void onLoad() {
		if(userLoginManagedBean.getUserAccountHashtable() == null) {
			try {
				boolean flag = FacesContext.getCurrentInstance().getExternalContext().isResponseCommitted();
				if(!flag) {
					FacesContext.getCurrentInstance().getExternalContext().redirect("/kenhsinhvien/faces/UserLogin.xhtml");
				}
			} catch (IOException e) {
				System.out.println(e.getMessage());
			}
		} else {
			if(userLoginManagedBean.getLoaiTaiKhoan() == KenhSinhVienContants.TAI_KHOAN_CHU_NHA_TRO) {
				this.setIsChuNhaTro("show");
			} else {
				this.setIsChuNhaTro("hide");
			}
			
			if(userLoginManagedBean.getLoaiTaiKhoan() == KenhSinhVienContants.TAI_KHOAN_CHU_QUAN_AN) {
				this.isChuQuanAn = "show";
			} else {
				this.isChuQuanAn = "hide";
			}
			
			if(userLoginManagedBean.getLoaiTaiKhoan() == KenhSinhVienContants.TAI_KHOAN_CONG_TY) {
				this.isCongTy = "show";
			} else {
				this.isCongTy = "hide";
			}
		}
	}

}
